public class SingleLinkedList{
    Node head;
    public SingleLinkedList(int... data){
        for(int i:data) this.add(i);
    }
    public int showIndexOf(int index) throws Exception{
        Node p=this.head;
        while(index-->1&&p!=null) p=p.next;
        if(p!=null) return p.data;
        else throw new Exception("越界");
    }
    public void add(int data){
        Node p=this.head;
        if(p==null) head=new Node(data,null);
        else{
            while(p.next!=null){
                p=p.next;
            }
            p.next=new Node(data,null);
        }
    }
    public void add(int... data){
        for(int i:data) this.add(i);
    }
    public void addIndexOf(int index,int data){
        Node p=this.head;
        while(index-->1&&p!=null) p=p.next;
        if(p==null) this.add(data);
        else{
            Node node =new Node(data, p.next);
            p.next=node;
        }
    }
    public void addIndexOf(int index,int... data){
        for(int i:data) this.addIndexOf(index, i);
    }
    public void remove(int index){
        Node p=this.head;
        while(index-->1&&p!=null) p=p.next;
        if(p!=null&&p.next!=null){
            p.next=p.next.next;
        }
    }
    public void remove(int index,int number){
        while(number-->0) this.remove(index);
    }
    @Override
    public String toString() {
        StringBuilder s=new StringBuilder();
        Node p=head;
        while(p!=null){
            s.append(p.data+", ");
            p=p.next;
        }
        return s.toString();
    }
}